using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class WhomILikeDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public WhomILikeDA()
		{
		}

		public WhomILikeDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the WhomILike table.
		/// </summary>
		public  int Insert(WhomILike whomILike)
		{
			ValidationUtility.ValidateArgument("whomILike", whomILike);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", whomILike.TenantID),
				new SqlParameter("@ProfileID", whomILike.ProfileID),
				new SqlParameter("@InterestedProfileID", whomILike.InterestedProfileID),
				new SqlParameter("@IsDeleted", whomILike.IsDeleted),
				new SqlParameter("@UpdateDate", whomILike.UpdateDate),
				new SqlParameter("@UpdatedBy", whomILike.UpdatedBy)
			};

			whomILike.LikeID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "WhomILikeInsert", parameters));
			return whomILike.LikeID;
		}

		/// <summary>
		/// Updates a record in the WhomILike table.
		/// </summary>
		public  int Update(WhomILike whomILike)
		{
			ValidationUtility.ValidateArgument("whomILike", whomILike);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@LikeID", whomILike.LikeID),
				new SqlParameter("@TenantID", whomILike.TenantID),
				new SqlParameter("@ProfileID", whomILike.ProfileID),
				new SqlParameter("@InterestedProfileID", whomILike.InterestedProfileID),
				new SqlParameter("@IsDeleted", whomILike.IsDeleted),
				new SqlParameter("@UpdateDate", whomILike.UpdateDate),
				new SqlParameter("@UpdatedBy", whomILike.UpdatedBy)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomILikeUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomILike table by its primary key.
		/// </summary>
		public  int Delete(int likeID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@LikeID", likeID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomILikeDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomILike table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomILikeDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomILike table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomILikeDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the WhomILike table.
		/// </summary>
		public  WhomILike Select(int likeID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@LikeID", likeID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomILikeSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeWhomILike(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the WhomILike table.
		/// </summary>
		public  List<WhomILike> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomILikeSelectAll", parameters))
			{
				List<WhomILike> whomILikeList = new List<WhomILike>();
				while (dataReader.Read())
				{
					WhomILike whomILike = MakeWhomILike(dataReader);
					whomILikeList.Add(whomILike);
				}

				return whomILikeList;
			}
		}

		/// <summary>
		/// Selects all records from the WhomILike table by a foreign key.
		/// </summary>
		public  List<WhomILike> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomILikeSelectAllByProfileID", parameters))
			{
				List<WhomILike> whomILikeList = new List<WhomILike>();
				while (dataReader.Read())
				{
					WhomILike whomILike = MakeWhomILike(dataReader);
					whomILikeList.Add(whomILike);
				}

				return whomILikeList;
			}
		}

		/// <summary>
		/// Selects all records from the WhomILike table by a foreign key.
		/// </summary>
		public  List<WhomILike> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomILikeSelectAllByTenantID", parameters))
			{
				List<WhomILike> whomILikeList = new List<WhomILike>();
				while (dataReader.Read())
				{
					WhomILike whomILike = MakeWhomILike(dataReader);
					whomILikeList.Add(whomILike);
				}

				return whomILikeList;
			}
		}

		/// <summary>
		/// Creates a new instance of the WhomILike class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  WhomILike MakeWhomILike(SqlDataReader dataReader)
		{
			WhomILike whomILike = new WhomILike();
			whomILike.LikeID = SqlClientUtility.GetInt32(dataReader, "LikeID", 0);
			whomILike.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			whomILike.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			whomILike.InterestedProfileID = SqlClientUtility.GetInt32(dataReader, "InterestedProfileID", 0);
			whomILike.IsDeleted = SqlClientUtility.GetBoolean(dataReader, "IsDeleted", false);
			whomILike.UpdateDate = SqlClientUtility.GetDateTime(dataReader, "UpdateDate", DateTime.Now);
			whomILike.UpdatedBy = SqlClientUtility.GetString(dataReader, "UpdatedBy", String.Empty);

			return whomILike;
		}

		#endregion
	}
}
